//Copyright (c) 2010, Goodwine & Tibia ML
//Licensed under new BSD License.

// Change example.
function indicatorOption(value) {
	var indicator = value;
	switch(value) {
		default:
		case 'icon':
			opHTML =
				'<img alt="Online" title="Online" src="./images/green icon.svg" height=16px;/> - '+
				'<img alt="Offline" title="Offline" src="./images/gray icon.svg" height=16px;/>';
			opText = '<span class="example">Example:</span>';
			$('#indicator_result').html(opText+opHTML);
		break;
		
		case 'text':
			opHTML = '<b style="color:green;">On</b>';
			opText = '<span class="example">Example:</span>';
			$("#indicator_result").html(opText+opHTML);
		break;
		
		case 'none':
			$("#indicator_result").html("");
		break;
	}
}

// Save the options.
function saveIndicatorOptions(indicators, disabled) {
	localStorage.indicator_disabled = disabled.checked;
	if(disabled.checked) {
		localStorage.indicator = 'none';
		_trackOption('Online Indicator', 'disabled');
	}
	else {
		for(var i in indicators)
			if(indicators[i].checked) {
				var indicator = indicators[i].value;
				break;
			}
		localStorage.indicator = indicator;
		_trackOption('Online Indicator', indicator);
	}
	enableIndicatorControls(false);
	alert('Guild Online/Offline indicator options saved successfully.');
}

// Load options.
function recallIndicatorOptions() {
	disabled = JSON.parse(localStorage.indicator_disabled);
	disable_indicator.checked = disabled;
	$('#indicator_option input[type*=radio]').each(function() {this.disabled = disabled;});
	localStorage.indicator = localStorage.indicator ? localStorage.indicator : 'icon';
	changeIndicatorRadios(localStorage.indicator);
	enableIndicatorControls(false);
}

function changeIndicatorRadios(indicator) {
	$('#'+indicator).click();
}

function disableIndicators(disabled) {
	$('#indicator_option input[type*=radio]').each(function() {this.disabled = disabled;});
}

function enableIndicatorControls(enabled) {
	enabled = enabled || false;
	$('#guild_ops .submit input').attr('disabled', !enabled);
}

$(function() {
	$('#guild_ops input').change(enableIndicatorControls).keydown(enableIndicatorControls);
	recallIndicatorOptions();
});
